package com.db.stexchem.client.gui;

import javax.swing.table.*;
import javax.swing.*;

import com.db.stexchem.message.ExecutionReport;
import java.awt.*;
import java.awt.event.*;

public class ExecutionTable extends JTable implements MouseListener {
  
  public ExecutionTable(ExecutionTableModel executionTableModel) {
    super(executionTableModel);
    addMouseListener(this);
  }
  
  public Component prepareRenderer(TableCellRenderer renderer, int row,
      int column) {
    ExecutionReport report = (ExecutionReport) ((ExecutionTableModel) dataModel)
        .getReport(row);
    
    boolean fullyFilled = report.isFullyFilled();
    
    DefaultTableCellRenderer r = (DefaultTableCellRenderer) renderer;
    r.setForeground(Color.black);
    
    if (fullyFilled)
      r.setBackground(Color.green);
    else
      r.setBackground(Color.yellow);
    
    return super.prepareRenderer(renderer, row, column);
  }
  
  public void mouseClicked(MouseEvent e) {
    if (e.getClickCount() != 2)
      return;
    int row = rowAtPoint(e.getPoint());
    ExecutionReport report = (ExecutionReport) ((ExecutionTableModel) dataModel)
        .getReport(row);
    // application.cancel(Execution);
  }
  
  public void mouseEntered(MouseEvent e) {
  }
  
  public void mouseExited(MouseEvent e) {
  }
  
  public void mousePressed(MouseEvent e) {
  }
  
  public void mouseReleased(MouseEvent e) {
  }
}
